# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: David Runge <dvzrv@archlinux.org>
# Contributor: Angel Velasquez <angvp@archlinux.org>
# Contributor: Felix Yan <felixonmars@archlinux.org>
# Contributor: Stéphane Gaudreault <stephane@archlinux.org>
# Contributor: Alexander Fehr <pizzapunk gmail com>
export CHECKFUNC=1

_pyname=pylint
pkgname=python-$_pyname
pkgver=2.17.7
pkgrel=1
pkgdesc='Analyzes Python code looking for bugs and signs of poor quality'
arch=(any)
url=https://pylint.pycqa.org
license=(GPL)
_pydeps=(astroid
         colorama
         dill
         isort
         mccabe
         platformdirs
         tomli # for python <3.11
         tomlkit)
depends=(python
         "${_pydeps[@]/#/python-}")
makedepends=(python-{build,installer}
             python-myst-parser
             python-setuptools
             python-sphinx{,-reredirects}
             python-wheel)
checkdepends=(mpdecimal
              python-gitpython
              python-py
              python-pytest{,-timeout,-benchmark})
optdepends=('graphviz: Enable output formats other than dot or vcg')
_archive="$_pyname-$pkgver"
source=("https://github.com/PyCQA/pylint/archive/v$pkgver/$_archive.tar.gz")
sha256sums=('13ee786f1fb226c2e66542c31c86e9597577072295766a50f3121f22a1b90acc')

prepare() {
	cd "$_archive"
	# Remove build time dependency pinning that conflicts with Arch packages
	sed -i -E '/^requires/s/~=[0-9.]+//g' pyproject.toml
	# Remove overly restrictive dependency pinning that ends up in runtime checks
	sed -i -e '/>=/{s/>.*//;p}' -e '/python_requires/d' setup.cfg
}

build() {
	cd "$_archive"
	python -m build -wn
	make PYTHONPATH="$PWD/build/lib" -C doc man
}

check() {
	local deselected=(
		--deselect tests/test_functional.py::test_functional
		--deselect tests/test_self.py::TestRunTC::test_do_not_import_files_from_local_directory
		--deselect tests/testutils/test_testutils_utils.py::test__test_environ_pythonpath_no_arg
		--deselect tests/benchmark/test_baseline_benchmarks.py
	)
	cd "$_archive"
	export PYTHONPATH="$PWD:$PWD/build/lib"
	pytest -vv --color=yes "${deselected[@]}"
}

package() {
	cd "$_archive"
	python -m installer -d "$pkgdir" dist/*.whl
	install -Dm0644 -t "$pkgdir/usr/share/man/man1/" doc/_build/man/*.1
}
